Skip to content

fix: backfill tool call data in chat stream conversion#2306

Open
MiaoZang wants to merge 1 commit into
Wei-Shaw:mainfrom
MiaoZang:upstream/responses-chat-tool-call-backfill
Open

fix: backfill tool call data in chat stream conversion#2306
MiaoZang wants to merge 1 commit into
Wei-Shaw:mainfrom
MiaoZang:upstream/responses-chat-tool-call-backfill

Conversation

@MiaoZang
Copy link
Copy Markdown

@MiaoZang MiaoZang commented May 8, 2026

Summary

  • Backfill function name and arguments when Responses streams emit them in response.function_call_arguments.done or response.output_item.done.
  • Track whether a tool call name/arguments have already been sent to avoid duplicate deltas.

Verification

  • go test ./internal/pkg/apicompat -run 'TestResponsesEventToChatChunks_ToolCall' -count=1
  • git diff --check

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@MiaoZang
Copy link
Copy Markdown
Author

MiaoZang commented May 9, 2026

I have read the CLA Document and I hereby sign the CLA

sakurawztlt added a commit to sakurawztlt/sub2api that referenced this pull request May 11, 2026
…m done events

Responses → ChatCompletions stream 转换时, tool call 的 name/arguments 不一定在 delta 阶段完整出现, 可能只在 function_call_arguments.done / output_item.done 才补齐. 客户侧之前看到 tool call 缺字段, 后续 tool_result missing 或工具链断裂.

修法: state 加 OutputIndexNameSent / OutputIndexArgsSeen 跟踪每个 tool call 的 name/args 已发情况, 在 *.done 事件时如果还没发就补齐.

只动 OpenAI 兼容层 (Responses ↔ ChatCompletions). Anthropic /v1/messages 路径仍保 toolu_xxx 形态不动, 不影响 cc-api 真 Claude tools.

3 unit test 全过 (Delta / ArgumentsDone / OutputItemDone backfill).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant